//
//  HomeViewController.swift
//  斗鱼直播Swift
//
//  Created by admin on 2018/2/23.
//  Copyright © 2018年 admin. All rights reserved.
//

import UIKit
private let titleViewHeight : CGFloat = 40
class HomeViewController: UIViewController {
    private lazy var pageTitleView : PageTitleView = {
        
        let frame = CGRect.init(x: 0, y: kStatusBarHeight+kStatusNavBarHeight, width: kScreenW, height: titleViewHeight)
        let titles = ["推荐","游戏","娱乐","趣玩"]
        let titleView = PageTitleView.init(frame: frame, titles: titles)
        titleView.backgroundColor = UIColor.white
        titleView.delegate = self
        
        return titleView
        
    }()
    private lazy var pageContentView : PageContentView = {
        //确定自控制qi
        let frame = CGRect.init(x: 0, y: pageTitleView.frame.maxY, width: kScreenW, height: kScreenH - pageTitleView.frame.maxY)
        var childVCs = [UIViewController]()
        childVCs.append(RecommendViewController())
        for _ in 0..<3 {
            let vc = UIViewController.init()
            vc.view.backgroundColor = UIColor.randomColor()
            childVCs.append(vc)
        }
        let contentView = PageContentView.init(frame: frame, childVCs: childVCs, parentVC: self)
        contentView.delegate = self
        return contentView
    }()
    override func viewDidLoad() {
        super.viewDidLoad()
            setupUI()
    }

}
extension HomeViewController : pageTitleViewDelegate{
    func pageTitleView(titleView: PageTitleView, index: Int) {
     pageContentView.index = index
    }
}
extension HomeViewController : PageContentViewDelegate {
    
    func pageContentView(contentcView: PageContentView, progress: CGFloat, sourceIndex: Int, targetIndex: Int) {
        
        self.pageTitleView.setTitleViewProgress(progress: progress, sourceIndex: sourceIndex, targetIndex: targetIndex)
        
    }
}
// mark 导航栏
extension HomeViewController {
    private func setupUI () {
        setupNav()
        view.addSubview(pageTitleView)
        view.addSubview(pageContentView)
    }
    
    private func setupNav () {
        let button = UIButton()
        button.setImage(UIImage.init(named: "logo"), for: .normal)
        button.sizeToFit()
        navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: button)
        
        let size = CGSize.init(width: 40, height: 40)
         let hisoryItem = UIBarButtonItem.init(imageName: "image_my_history", hightImageName: "Image_my_history_click", size: size)
        
        let searchItem = UIBarButtonItem.createItem(imageName: "btn_search", hightImageName: "btn_search_clicked", size: size)
        
        let qrItem = UIBarButtonItem.createItem(imageName: "Image_scan", hightImageName: "Image_scan_click", size: size)

        navigationItem.rightBarButtonItems = [hisoryItem,searchItem,qrItem]
    }
    
    
}
